package com.ruoyi.web.controller.order;


import com.ruoyi.order.domain.OrderPromotion;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.order.service.IOrderPromotionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 支付优惠Controller
 *
 * @author HHAOYU
 * @date 2020-12-14
 */
@RestController
@RequestMapping("/order/orderPromotion")
public class OrderPromotionController extends BaseController
{
    @Autowired
    private IOrderPromotionService orderPromotionService;

    /**
     * 查询支付优惠列表
     */
    @PreAuthorize("@ss.hasPermi('cinema:orderPromotion:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderPromotion orderPromotion)
    {
        startPage();
        List<OrderPromotion> list = orderPromotionService.selectOrderPromotionList(orderPromotion);
        return getDataTable(list);
    }

    /**
     * 导出支付优惠列表
     */
    @PreAuthorize("@ss.hasPermi('cinema:orderPromotion:export')")
    @Log(title = "支付优惠", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OrderPromotion orderPromotion)
    {
        List<OrderPromotion> list = orderPromotionService.selectOrderPromotionList(orderPromotion);
        ExcelUtil<OrderPromotion> util = new ExcelUtil<OrderPromotion>(OrderPromotion.class);
        return util.exportExcel(list, "orderPromotion");
    }

    /**
     * 获取支付优惠详细信息
     */
    @PreAuthorize("@ss.hasPermi('cinema:orderPromotion:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(orderPromotionService.selectOrderPromotionById(id));
    }

    /**
     * 新增支付优惠
     */
    @PreAuthorize("@ss.hasPermi('cinema:orderPromotion:add')")
    @Log(title = "支付优惠", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderPromotion orderPromotion)
    {
        return toAjax(orderPromotionService.insertOrderPromotion(orderPromotion));
    }

    /**
     * 修改支付优惠
     */
    @PreAuthorize("@ss.hasPermi('cinema:orderPromotion:edit')")
    @Log(title = "支付优惠", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderPromotion orderPromotion)
    {
        return toAjax(orderPromotionService.updateOrderPromotion(orderPromotion));
    }

    /**
     * 删除支付优惠
     */
    @PreAuthorize("@ss.hasPermi('cinema:orderPromotion:remove')")
    @Log(title = "支付优惠", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderPromotionService.deleteOrderPromotionByIds(ids));
    }
}
